//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>
package org.jpgolay.wi.realestate;

import java.math.BigDecimal;
import net.sf.jasperreports.engine.*;
import org.jpgolay.wi.agency.Agency;
import org.jpgolay.wi.util.Parameter;
import org.jpgolay.wi.util.WIDate;

// Referenced classes of package org.jpgolay.wi.realestate:
//            RealEstate
public class RealEstatePrintDataSource
        implements JRDataSource {

    public RealEstatePrintDataSource(RealEstate realestate, Agency agency, Parameter param) {
        this.realestate = realestate;
        this.agency = agency;
        this.param = param;
        date = new WIDate();
        count = 26;
    }

    public boolean next()
            throws JRException {
        return count > 0;
    }

    public Object getFieldValue(JRField field)
            throws JRException {
        String fieldname = field.getName();
        String value = null;
        if ("company".equals(fieldname)) {
            value = agency.getCompagny();
        } else if ("addrLn1".equals(fieldname)) {
            value = agency.getAddrLn1();
        } else if ("addrLn2".equals(fieldname)) {
            value = agency.getAddrLn2();
        } else if ("city".equals(fieldname)) {
            value = agency.getCity();
        } else if ("zip".equals(fieldname)) {
            value = agency.getZip();
        } else if ("tel1".equals(fieldname)) {
            if (agency.getTel1() != null) {
                value = "T\351l : " + agency.getTel1();
            }
        } else if ("tel2".equals(fieldname)) {
            if (agency.getTel2() != null) {
                value = "T\351l : " + agency.getTel2();
            }
        } else if ("fax".equals(fieldname)) {
            if (agency.getFax() != null) {
                value = "Fax : " + agency.getFax();
            }
        } else if ("email".equals(fieldname)) {
            if (agency.getEmail() != null) {
                value = "Email : " + agency.getEmail();
            }
        } else if ("id".equals(fieldname)) {
            if (realestate.getId() != null) {
                value = "R\351f\351rence : " + realestate.getId().toString();
            }
        } else if ("batch".equals(fieldname)) {
            if (realestate.getBatch() != null) {
                value = "Lot : " + realestate.getBatch();
            }
        } else if ("internalRef".equals(fieldname)) {
            if (realestate.getRefInternal() != null) {
                value = "R\351f\351rence (interne) : " + realestate.getRefInternal();
            }
        } else if ("date".equals(fieldname)) {
            if (realestate.getCreate() != null) {
                value = "WIDate : " + date.toPlain(realestate.getCreate());
            }
        } else if ("residence".equals(fieldname)) {
            if (realestate.getResidance() != null) {
                value = "R\351sidence : " + realestate.getResidance();
            }
        } else if ("realestateAddrLn1".equals(fieldname)) {
            value = realestate.getAddrLn1();
        } else if ("realestateAddrLn2".equals(fieldname)) {
            value = realestate.getAddrLn2();
        } else if ("realestateZip".equals(fieldname)) {
            value = realestate.getZip();
        } else if ("realestateCity".equals(fieldname)) {
            value = realestate.getCounty();
        } else if ("sort".equals(fieldname)) {
            value = realestate.getSort();
        } else if ("type".equals(fieldname)) {
            value = realestate.getType();
        } else if ("sh".equals(fieldname)) {
            value = realestate.getSurfaceFloor().toString();
        } else if ("dateDispo".equals(fieldname)) {
            value = date.toPlain(realestate.getAvailability());
        } else if ("rent".equals(fieldname)) {
            value = realestate.getRent().setScale(2).toPlainString();
        } else if ("caution".equals(fieldname)) {
            value = realestate.getDeposit().setScale(2).toPlainString();
        } else if ("agencyFees".equals(fieldname)) {
            value = realestate.getAgencyFees().setScale(2).toPlainString();
        } else if ("notes".equals(fieldname)) {
            value = realestate.getExitCustomer();
        }
        count--;
        return value;
    }
    private RealEstate realestate;
    private Agency agency;
    private Parameter param;
    private WIDate date;
    private int count;
}
